package study.oss测试;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.OSSObjectSummary;
import com.aliyun.oss.model.ObjectListing;

import java.io.File;

/**
 * @Author 刘伟涛
 * @Date 2024/6/28 15:15
 **/
public class ListObjects {
    public static void main(String[] args) {
        // 设置阿里云OSS访问凭证
        String endpoint = "http://oss-cn-shenzhen.aliyuncs.com";
        String accessKeyId = "LTAI5tLtxS5UW8HR9MFKnb5P";
        String accessKeySecret = "62oVaKMuNerriUZHke1IKHz5VLTzIF";

        // 创建OSSClient实例
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        String bucketName = "lims2-0";
//    String keyName = "temposs.doc";
        String pre = "dev";
        String downloadFilePath =  pre + "c41b59843311424496131de02e6cd33c.doc"; // 修改为你的下载路径
//        File file = File.createTempFile("temposs", ".doc");

        // 列出存储桶中的对象
        ObjectListing objectListing = ossClient.listObjects(bucketName);
        for (OSSObjectSummary objectSummary : objectListing.getObjectSummaries()) {
            System.out.println(" - " + objectSummary.getKey() + "  " + "(size = " + objectSummary.getSize() + ")");
        }

        // 关闭OSSClient
        ossClient.shutdown();
    }
}
